package BaseObject.signleTon;

/**
 * ClassName: SingleTon02 懒汉式
 * Package: BaseObject.signleTon
 * Description:
 *
 * @Author Linshio
 * @Create 2025/3/22 11:13
 */
public class SingleTon02 {
    public static void main(String[] args) {
        Cat instance = Cat.getInstance();
        Cat instance1 = Cat.getInstance();
        System.out.println("instance = " + instance);
        System.out.println("instance1 = " + instance1);
        System.out.println(instance1==instance);
    }
}

class Cat{
    private String name;
    private static Cat cat;
    private Cat(String name){
        this.name = name;
    }

    public static Cat getInstance(){
        if (cat==null){
            cat = new Cat("AZ");
        }
        return cat;
    }

    @Override
    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                '}';
    }
}
